﻿using Business;
using Model;
using Public;
using Public.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using wochu.DPS.API.Infrastructure;

namespace wochu.DPS.API.Controllers
{
    public class OrderCheckController : ApiController
    {
        /// <summary>
        /// 根据商品编号获取分拣灯无法拍灭导致的订单未分拣信息
        /// </summary>
        /// <param name="GoodsCode">商品编号</param>
        /// <param name="Flag">00-未亮灯，01-亮灯未拍，00-亮灯拍灭</param>
        /// <returns></returns>
        [HttpGet]
        public HttpResponseMessage GetOrderDetInfo(DateTime RationDate,string BatchNO,string GoodsCode, string Flag = "01")
        {
            var result = new BOrder().GetUndealedOrderInfo(RationDate, BatchNO,GoodsCode, Flag);
            SysSetting sysSet = new SysSetting();
            if (result == null || result.Count<=0)
            {
                sysSet.Key = Consts.strFalse;
                sysSet.Value = "该商品暂无亮灯未拍订单信息";
                return ResultsExtensions.GetFailJson(sysSet);
                
            }
            else
            {
                return ResultsExtensions.GetSuccessJson(result);
            }
        
        }

        [HttpPost]
        public HttpResponseMessage PostOrderDetInfo(List<UnDealedOrderInfo> lstUnDealedOrderDet)
        {
            SysSetting sysSet = new SysSetting();
            if(lstUnDealedOrderDet==null || lstUnDealedOrderDet.Count<=0)
            {
                sysSet.Key = Consts.strFalse;
                sysSet.Value = "参数解析错误，请检查参数";
                return ResultsExtensions.GetFailJson(sysSet);

            }
            else
            {
                var _result=new BOrder().UpdateUndealedOrderInfo(lstUnDealedOrderDet);
                if (_result)
                {
                    return ResultsExtensions.GetSuccessJson(_result);
                }
                else
                {
                    sysSet.Key = Consts.strFalse;
                    sysSet.Value = "提交失败，请联系管理员";
                    return ResultsExtensions.GetFailJson(sysSet);
                }
            }

        }
    }
}
